package chapter8;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/4/12 10:14
 */
class Useful {
    public void f() {
    }

    public void g() {
    }
}

class MoreUseful extends Useful {
    @Override
    public void f() {
        super.f();
    }

    @Override
    public void g() {
        super.g();
    }

    public void h() {
    }

    public void v() {
    }

    public void w() {
    }
}

public class RTTI {
    public static void main(String[] args) {
        Useful[] x = {new Useful(), new MoreUseful()};
        x[0].f();
        x[1].g();

        //Compile time: method not found in Useful
        //x[1].u();

        // Downcast/RTTI
        ((MoreUseful) x[1]).h();
        // Execption thrown
        ((MoreUseful) x[0]).h();
    }
}
